package com.intelligentclass.services;

import com.intelligentclass.entity.Student;
import com.intelligentclass.entity.Teacher;
import com.intelligentclass.entity.Teaching;
import com.intelligentclass.repositories.TeachingRespository;
import jakarta.persistence.EntityNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeachingService {

    private TeachingRespository teachingRepository;

    public TeachingService(TeachingRespository teachingRepository) {
        this.teachingRepository = teachingRepository;
    }

    public List<Teacher> getAllTeachers(int cid){
        return teachingRepository.findAllTeacher(cid);
    }

    public List<Student> getAllStudents(int cid){
        try {
            Teaching t = teachingRepository.getReferenceById(cid);
            return t.getStudentList();
        }catch (EntityNotFoundException e){
            return null;
        }
    }

    public Teaching searchTeaching(int cid){
        return teachingRepository.findById(cid).orElse(null);
    }
}
